package org.jackysoft.struts2.business;
import org.joda.time.DateTime;

import java.io.ByteArrayInputStream;
import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.MonthPlanning;
import org.jackysoft.service.ArmMonthlyPlanService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.jackysoft.util.FileInfo;
import org.jackysoft.util.HttpUtil;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


@Controller
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Namespace("/monthplanning")
public class MonthPlanningAction 
extends UtilsCRUDAction<MonthPlanning> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6123875878615118093L;
	private ArmMonthlyPlanService service;
	private MonthPlanning bean;
	private Collection<MonthPlanning> beans;
	private DateTime actionDate;
	private Integer year;
	private Integer month;
		
	
	public String importfileplan() throws Exception{
		service.importPlanning(upLoad,actionDate);		
		return "saveok";
	}
	
	public String importplan() throws Exception{		
		service.importPlanning(bean.getCreateDate());
		return "saveok";
	}
	
	public String downloadcur() throws Exception{	
	    FileInfo fi 	=  service.download(actionDate);
	    inputStream 	=  new ByteArrayInputStream(fi.getData());
	    contentLength 	=  fi.getDataLength();
		upLoadFileName 	=  fi.getTitle();
		contentType     =  HttpUtil.extToMimeType("xls");
	    return DOWNLOAD;
	}
	
	public void setBean(MonthPlanning bean){
	     this.bean = bean;
	}
	public MonthPlanning getBean(){
	     return this.bean;
	}
	public void setBeans(Collection<MonthPlanning> beans){
	
	     this.beans = beans;
	}
	public Collection<MonthPlanning> getBeans(){
	     return this.beans;
	}
	
	@Resource
	public void setService(ArmMonthlyPlanService service) {
		this.service = service;
		this.setDataProvider(service);
	}
	
	public ArmMonthlyPlanService getService() {
		return service;
	}

	public void setActionDate(DateTime actionDate) {
		this.actionDate = actionDate;
	}

	public DateTime getActionDate() {
		return actionDate;
	}	
	
	public Integer getYear() {
		return year;
	}


	public void setYear(Integer year) {
		this.year = year;
	}


	public Integer getMonth() {
		return month;
	}


	public void setMonth(Integer month) {
		this.month = month;
	}
}